<?php

if (!defined('EXPONENT')) exit('');

/**
 * Media Duration Control
 *
 * @author Immanuel192
 * @copyright 2008 - 2009 ABSoft
 * @version 0.1
 *
 * @package Subsystems
 * @subpackage Forms
 */

/**
 * Manually include the class file for formcontrol, for PHP4
 * (This does not adversely affect PHP5)
 */
require_once(BASE."subsystems/forms/controls/formcontrol.php");

/**
 * Media Duration Control
 *
 * @package Subsystems
 * @subpackage Forms
 */
class mediatime_control extends formcontrol {
	
	function name() { return "Media Duration Control"; }
	function isSimpleControl() { return true; }
	function getFieldDefinition() {
		return array(
			DB_FIELD_TYPE=>DB_DEF_STRING,
			DB_FIELD_LEN=>255);
	}
	
	function mediatime_control($duration, $disable = false) { // $duration by seconds
		// calculate how many seconds, minutes, hours
		$this->duration = $duration;
    $hours=$duration/3600;
		$duration=$duration % 3600;
		$mins = $duration/60;
		$duration=$duration % 60;
		$seconds=$duration;
		
		$this->hours=$hours;
		$this->mins=$mins;
		$this->seconds=$seconds;
		
		$this->disable = $disable;
		
	}
	
	function controlToHTML($name) {
	 $disable="";
   if ($this->disable)
    $disable=" disabled ";
   // javascript
   $html="<script language='Javascript'>
        function control_{$name}(){
         var t=document.getElementById('{$name}');
         var x=document.getElementById('{$name}_h');
         var y=document.getElementById('{$name}_m');
         var z=document.getElementById('{$name}_s');
         if (!IsNumeric(x.value))
         { x.focus(); t.value=0; return;}
         else if (!IsNumeric(y.value))
         { y.focus(); t.value=0; return;}
         else if (!IsNumeric(z.value))
         { z.focus(); t.value=0; return;}
         t.value=x.value*3600 + y.value*60 + z.value;
        }
   </script>";
   // end of javascript
	 $html.="<input type=hidden id='".$name."' name='".$name."' value=".$this->duration.">
      <input type=text id='".$name."_h' value={$this->hours}   {$disable} size=1 style='text-align: right;' alt='Hour' title='Hour' onkeypress='control_{$name}()' maxlength=2><b>:</b>";
   $html.="<input onkeypress='control_{$name}()' {$disable} type=text id='".$name."_m' value={$this->mins} size=1 style='text-align: right;' alt='Minute' title='Minute'  maxlength=2><b>:</b>";
   $html.="<input {$disable} type=text id='".$name."_s' value={$this->seconds} size=1 style='text-align: right;' alt='Seconds' title='Seconds' onkeypress='control_{$name}()' maxlength=2>";	
		return $html;
	}
	
	function form($object) {
		return;
	}
	
	function update($values, $object) {
		return;
	}
}

?>
